package com.example.demo.service;

import com.example.demo.dao.mapper.BlogMapper;
import com.example.demo.dao.pojo.BlogInfo;
import com.example.demo.vo.BlogVo;
import com.example.demo.vo.Result;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class BlogService {

    @Autowired
    private BlogMapper blogMapper;

    /**
     * 分页查询文章列表
     * @param params
     * @return
     */
//    public Result listBlog(PageParams params){
//        List<BlogInfo> records = blogMapper.selectAll(params.getPage(), params.getPageSize());
//        List<BlogVo> blogVoList = copyList(records);
//        return Result.success(blogVoList);
//    }

    private List<BlogVo> copyList(List<BlogInfo> records){
        List<BlogVo> blogVoList = new ArrayList<>();
        for (BlogInfo record : records) {
            blogVoList.add(copy(record));
        }
        return blogVoList;
    }

    private BlogVo copy(BlogInfo blogInfo){
        BlogVo blogVo = new BlogVo();
        BeanUtils.copyProperties(blogInfo, blogVo);
        return blogVo;
    }

    /**
     * 查看文章详情
     * 1.
     * @param id
     * @return
     */
    public Result findBlogById(int id) {
        BlogInfo blogInfo = blogMapper.selectById(id);
        return null;
    }
}
